package com.gitee.wsl.mathematics.statistics.simplify


import kotlin.test.Test
import kotlin.test.assertEquals

class SimplifyTest {
    @Test
    fun FullDatasetTest() {
        assertEquals(expected = simplified, actual = points.simplify(5.0))
    }

    @Test
    fun NoChangeIfOnlyOnePoint() {
        val input = listOf(Point2D(1.0, 2.0))
        assertEquals(expected = input, actual = input.simplify())
    }

    @Test
    fun ReturnEmptyWhenInputEmpty() {
        assertEquals(expected = emptyList(), actual = emptyList<Point2D>().simplify())
    }
}

class Point2D(val x: Double, val y: Double) {
    operator fun component1() = x
    operator fun component2() = y
}

private fun List<Point2D>.simplify(tolerance: Double = 1.0, highestQuality: Boolean = false): List<Point2D> {
    return simplify(
        tolerance = tolerance,
        highestQuality = highestQuality,
        xExtractor = { it.x },
        yExtractor = { it.y }
    )
}

val points = listOf(
    Point2D(224.55, 250.15),
    Point2D(226.91, 244.19),
    Point2D(233.31, 241.45),
    Point2D(234.98, 236.06),
    Point2D(244.21, 232.76),
    Point2D(262.59, 215.31),
    Point2D(267.76, 213.81),
    Point2D(273.57, 201.84),
    Point2D(273.12, 192.16),
    Point2D(277.62, 189.03),
    Point2D(280.36, 181.41),
    Point2D(286.51, 177.74),
    Point2D(292.41, 159.37),
    Point2D(296.91, 155.64),
    Point2D(314.95, 151.37),
    Point2D(319.75, 145.16),
    Point2D(330.33, 137.57),
    Point2D(341.48, 139.96),
    Point2D(369.98, 137.89),
    Point2D(387.39, 142.51),
    Point2D(391.28, 139.39),
    Point2D(409.52, 141.14),
    Point2D(414.82, 139.75),
    Point2D(427.72, 127.30),
    Point2D(439.60, 119.74),
    Point2D(474.93, 107.87),
    Point2D(486.51, 106.75),
    Point2D(489.20, 109.45),
    Point2D(493.79, 108.63),
    Point2D(504.74, 119.66),
    Point2D(512.96, 122.35),
    Point2D(518.63, 120.89),
    Point2D(524.09, 126.88),
    Point2D(529.57, 127.86),
    Point2D(534.21, 140.93),
    Point2D(539.27, 147.24),
    Point2D(567.69, 148.91),
    Point2D(575.25, 157.26),
    Point2D(580.62, 158.15),
    Point2D(601.53, 156.85),
    Point2D(617.74, 159.86),
    Point2D(622.00, 167.04),
    Point2D(629.55, 194.60),
    Point2D(638.90, 195.61),
    Point2D(641.26, 200.81),
    Point2D(651.77, 204.56),
    Point2D(671.55, 222.55),
    Point2D(683.68, 217.45),
    Point2D(695.25, 219.15),
    Point2D(700.64, 217.98),
    Point2D(703.12, 214.36),
    Point2D(712.26, 215.87),
    Point2D(721.49, 212.81),
    Point2D(727.81, 213.36),
    Point2D(729.98, 208.73),
    Point2D(735.32, 208.20),
    Point2D(739.94, 204.77),
    Point2D(769.98, 208.42),
    Point2D(779.60, 216.87),
    Point2D(784.20, 218.16),
    Point2D(800.24, 214.62),
    Point2D(810.53, 219.73),
    Point2D(817.19, 226.82),
    Point2D(820.77, 236.17),
    Point2D(827.23, 236.16),
    Point2D(829.89, 239.89),
    Point2D(851.00, 248.94),
    Point2D(859.88, 255.49),
    Point2D(865.21, 268.53),
    Point2D(857.95, 280.30),
    Point2D(865.48, 291.45),
    Point2D(866.81, 298.66),
    Point2D(864.68, 302.71),
    Point2D(867.79, 306.17),
    Point2D(859.87, 311.37),
    Point2D(860.08, 314.35),
    Point2D(858.29, 314.94),
    Point2D(858.10, 327.60),
    Point2D(854.54, 335.40),
    Point2D(860.92, 343.00),
    Point2D(856.43, 350.15),
    Point2D(851.42, 352.96),
    Point2D(849.84, 359.59),
    Point2D(854.56, 365.53),
    Point2D(849.74, 370.38),
    Point2D(844.09, 371.89),
    Point2D(844.75, 380.44),
    Point2D(841.52, 383.67),
    Point2D(839.57, 390.40),
    Point2D(845.59, 399.05),
    Point2D(848.40, 407.55),
    Point2D(843.71, 411.30),
    Point2D(844.09, 419.88),
    Point2D(839.51, 432.76),
    Point2D(841.33, 441.04),
    Point2D(847.62, 449.22),
    Point2D(847.16, 458.44),
    Point2D(851.38, 462.79),
    Point2D(853.97, 471.15),
    Point2D(866.36, 480.77)
)

val simplified = listOf(
    Point2D(224.55, 250.15),
    Point2D(267.76, 213.81),
    Point2D(296.91, 155.64),
    Point2D(330.33, 137.57),
    Point2D(409.52, 141.14),
    Point2D(439.60, 119.74),
    Point2D(486.51, 106.75),
    Point2D(529.57, 127.86),
    Point2D(539.27, 147.24),
    Point2D(617.74, 159.86),
    Point2D(629.55, 194.60),
    Point2D(671.55, 222.55),
    Point2D(727.81, 213.36),
    Point2D(739.94, 204.77),
    Point2D(769.98, 208.42),
    Point2D(779.60, 216.87),
    Point2D(800.24, 214.62),
    Point2D(820.77, 236.17),
    Point2D(859.88, 255.49),
    Point2D(865.21, 268.53),
    Point2D(857.95, 280.30),
    Point2D(867.79, 306.17),
    Point2D(859.87, 311.37),
    Point2D(854.54, 335.40),
    Point2D(860.92, 343.00),
    Point2D(849.84, 359.59),
    Point2D(854.56, 365.53),
    Point2D(844.09, 371.89),
    Point2D(839.57, 390.40),
    Point2D(848.40, 407.55),
    Point2D(839.51, 432.76),
    Point2D(853.97, 471.15),
    Point2D(866.36, 480.77)
)